package com.huang.controller;

import com.huang.Handler.UserHandler;
import com.huang.pojo.Msg;
import com.huang.pojo.User;
import com.huang.pojo.UserException;
import com.sun.java.browser.plugin2.liveconnect.v1.Result;
import com.sun.net.httpserver.Authenticator;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/validate")
    public void validate(@Valid  User user, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            FieldError fieldError = bindingResult.getFieldError();
             Msg.error(fieldError.getField(),fieldError.getDefaultMessage());
            }
    }
}
